package org.jtb.mensawotd;

import java.util.List;

import android.app.Activity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
	
	private Activity context;
	private List<HistoryItem> items;

	HistoryAdapter(Activity context, List<HistoryItem> items) {
		super(context, R.layout.history_item, items);

		this.context = context;
		this.items = items;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		if (convertView != null) {
			view = convertView;
		} else {
			LayoutInflater inflater = context.getLayoutInflater();
			view = inflater.inflate(R.layout.history_item, null);
		}

		HistoryItem item = items.get(position);
		
		TextView wordText = (TextView) view.findViewById(R.id.word_text);
		wordText.setText(Html.fromHtml(item.getWord()));

		TextView dateText = (TextView) view.findViewById(R.id.date_text);
		dateText.setText(item.getDateString(true));
		
		return view;
	}
}
